<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订票功能测试</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .test-container {
            max-width: 800px;
            margin: 50px auto;
            padding: 30px;
            background: white;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .test-section {
            margin-bottom: 30px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        .success { color: #28a745; }
        .error { color: #dc3545; }
        .info { color: #17a2b8; }
    </style>
</head>
<body class="bg-light">
    <div class="test-container">
        <h1 class="text-center mb-4">🔧 订票功能测试页面</h1>
        
        <div class="test-section">
            <h3>📋 测试信息</h3>
            <p><strong>当前时间：</strong><%= new java.util.Date() %></p>
            <p><strong>项目路径：</strong><%= request.getContextPath() %></p>
            <p><strong>用户登录状态：</strong>
                <c:choose>
                    <c:when test="${not empty sessionScope.user}">
                        <span class="success">✅ 已登录 (${sessionScope.user.username})</span>
                    </c:when>
                    <c:otherwise>
                        <span class="error">❌ 未登录</span>
                    </c:otherwise>
                </c:choose>
            </p>
        </div>
        
        <div class="test-section">
            <h3>🔗 测试链接</h3>
            <div class="row">
                <div class="col-md-6">
                    <h5>基础功能测试</h5>
                    <ul class="list-unstyled">
                        <li><a href="${pageContext.request.contextPath}/movies" class="btn btn-sm btn-outline-primary mb-2">电影列表</a></li>
                        <li><a href="${pageContext.request.contextPath}/showtimes?movieId=1" class="btn btn-sm btn-outline-primary mb-2">场次列表</a></li>
                        <li><a href="${pageContext.request.contextPath}/login" class="btn btn-sm btn-outline-primary mb-2">用户登录</a></li>
                    </ul>
                </div>
                <div class="col-md-6">
                    <h5>订票功能测试</h5>
                    <ul class="list-unstyled">
                        <li><a href="${pageContext.request.contextPath}/user/booking?showtimeId=1" class="btn btn-sm btn-outline-success mb-2">订票测试1</a></li>
                        <li><a href="${pageContext.request.contextPath}/user/booking?showtimeId=2" class="btn btn-sm btn-outline-success mb-2">订票测试2</a></li>
                        <li><a href="${pageContext.request.contextPath}/user/booking?showtimeId=13" class="btn btn-sm btn-outline-success mb-2">订票测试13</a></li>
                    </ul>
                </div>
            </div>
        </div>
        
        <div class="test-section">
            <h3>🛠️ 手动测试步骤</h3>
            <ol>
                <li><strong>登录测试：</strong>
                    <c:if test="${empty sessionScope.user}">
                        <a href="${pageContext.request.contextPath}/login" class="btn btn-sm btn-warning">先登录</a>
                    </c:if>
                    <c:if test="${not empty sessionScope.user}">
                        <span class="success">✅ 已登录</span>
                    </c:if>
                </li>
                <li><strong>场次测试：</strong>
                    <a href="${pageContext.request.contextPath}/showtimes?movieId=1" class="btn btn-sm btn-info">查看场次</a>
                </li>
                <li><strong>订票测试：</strong>点击上面的订票测试链接</li>
                <li><strong>错误诊断：</strong>如果出现404，检查控制台错误信息</li>
            </ol>
        </div>
        
        <div class="test-section">
            <h3>🔍 常见问题诊断</h3>
            <div class="accordion" id="troubleshootAccordion">
                <div class="accordion-item">
                    <h2 class="accordion-header" id="headingOne">
                        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne">
                            问题1：点击订票后显示404
                        </button>
                    </h2>
                    <div id="collapseOne" class="accordion-collapse collapse show" data-bs-parent="#troubleshootAccordion">
                        <div class="accordion-body">
                            <strong>可能原因：</strong>
                            <ul>
                                <li>BookingServlet映射问题</li>
                                <li>用户未登录被LoginFilter拦截</li>
                                <li>数据库连接问题</li>
                                <li>依赖的DAO类有问题</li>
                            </ul>
                            <strong>解决方案：</strong>
                            <ul>
                                <li>检查web.xml中的servlet映射</li>
                                <li>确保用户已登录</li>
                                <li>查看Tomcat控制台错误日志</li>
                            </ul>
                        </div>
                    </div>
                </div>
                
                <div class="accordion-item">
                    <h2 class="accordion-header" id="headingTwo">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo">
                            问题2：页面显示但没有座位信息
                        </button>
                    </h2>
                    <div id="collapseTwo" class="accordion-collapse collapse" data-bs-parent="#troubleshootAccordion">
                        <div class="accordion-body">
                            <strong>可能原因：</strong>
                            <ul>
                                <li>数据库中缺少seats表数据</li>
                                <li>SeatDAO查询失败</li>
                                <li>场次ID不存在</li>
                            </ul>
                            <strong>解决方案：</strong>
                            <ul>
                                <li>执行数据库修复脚本</li>
                                <li>检查场次ID是否有效</li>
                                <li>查看控制台错误信息</li>
                            </ul>
                        </div>
                    </div>
                </div>
                
                <div class="accordion-item">
                    <h2 class="accordion-header" id="headingThree">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree">
                            问题3：登录后仍然无法访问
                        </button>
                    </h2>
                    <div id="collapseThree" class="accordion-collapse collapse" data-bs-parent="#troubleshootAccordion">
                        <div class="accordion-body">
                            <strong>可能原因：</strong>
                            <ul>
                                <li>Session未正确设置</li>
                                <li>LoginFilter配置问题</li>
                                <li>用户权限不足</li>
                            </ul>
                            <strong>解决方案：</strong>
                            <ul>
                                <li>重新登录</li>
                                <li>清除浏览器缓存</li>
                                <li>检查用户角色设置</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="test-section">
            <h3>📞 获取帮助</h3>
            <p>如果以上测试都失败，请提供以下信息：</p>
            <ul>
                <li>具体的错误信息或截图</li>
                <li>浏览器控制台的错误信息</li>
                <li>Tomcat控制台的错误日志</li>
                <li>当前的访问URL</li>
            </ul>
        </div>
        
        <div class="text-center">
            <a href="${pageContext.request.contextPath}/test.jsp" class="btn btn-secondary">返回主测试页面</a>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
